/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.sys.web.user;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.sys.entity.user.HkUserProductImg;
import com.thinkgem.jeesite.modules.hk.sys.service.user.HkUserProductImgService;

/**
 * 用户产品图片Controller
 * @author 罗天文
 * @version 2018-06-20
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/user/hkUserProductImg")
public class HkUserProductImgController extends BaseController {

	@Autowired
	private HkUserProductImgService hkUserProductImgService;
	
	@ModelAttribute
	public HkUserProductImg get(@RequestParam(required=false) String id) {
		HkUserProductImg entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkUserProductImgService.get(id);
		}
		if (entity == null){
			entity = new HkUserProductImg();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:user:hkUserProductImg:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkUserProductImg hkUserProductImg, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkUserProductImg> page = hkUserProductImgService.findPage(new Page<HkUserProductImg>(request, response), hkUserProductImg); 
		model.addAttribute("page", page);
		return "hk/sys/user/hkUserProductImgList";
	}

	@RequiresPermissions("sys:user:hkUserProductImg:view")
	@RequestMapping(value = "form")
	public String form(HkUserProductImg hkUserProductImg, Model model) {
		model.addAttribute("hkUserProductImg", hkUserProductImg);
		return "hk/sys/user/hkUserProductImgForm";
	}

	@RequiresPermissions("sys:user:hkUserProductImg:edit")
	@RequestMapping(value = "save")
	public String save(HkUserProductImg hkUserProductImg, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkUserProductImg)){
			return form(hkUserProductImg, model);
		}
		hkUserProductImgService.save(hkUserProductImg);
		addMessage(redirectAttributes, "保存用户产品图片成功");
		return "redirect:"+Global.getAdminPath()+"/sys/user/hkUserProductImg/?repage";
	}
	
	@RequiresPermissions("sys:user:hkUserProductImg:edit")
	@RequestMapping(value = "delete")
	public String delete(HkUserProductImg hkUserProductImg, RedirectAttributes redirectAttributes) {
		hkUserProductImgService.delete(hkUserProductImg);
		addMessage(redirectAttributes, "删除用户产品图片成功");
		return "redirect:"+Global.getAdminPath()+"/sys/user/hkUserProductImg/?repage";
	}

}